//
// Created by heqian on 17-8-2.
//
#ifndef AUTOMAHJONG_NATIVE_LIB_H
#define AUTOMAHJONG_NATIVE_LIB_H

#include <jni.h>
#include <string>
#include <android/log.h>
#include "image/CodeImage.h"
#include "mahjong/Mahjong.h"
#include <thread>

using namespace img;
using namespace mahjong;

extern "C" {

JNIEXPORT void JNICALL
Java_mahjong_auto_com_os_Mahjong_discern(JNIEnv *env, jclass type, jobject bitmap);
JNIEXPORT void JNICALL Java_mahjong_auto_com_os_Mahjong_init(JNIEnv *env, jclass type);
JNIEXPORT void JNICALL Java_mahjong_auto_com_os_Mahjong_destroy(JNIEnv *env, jclass type);
JNIEXPORT void JNICALL
Java_mahjong_auto_com_os_Mahjong_test(JNIEnv *env, jclass type, jobject bitmap);


}

class CodeImg : public CodeImage {
protected:
    virtual Prt<Image> loadImage(const string &path) override;
};

class JniEnv {
public:
    JniEnv();

    virtual ~JniEnv();

    JNIEnv *operator->();

    bool isNULL();

    JNIEnv *operator*();

    int getVersion() const;

private:
    JNIEnv *mEnv;
    bool mAttated;
    int mVersion;
};

class Call : public Callinterface {
public:

    Call();

    virtual void info(Prt<BoardInfo> &info) override;

    virtual bool simulateClick(int x, int y) override;

    jobject getUserBoard(Prt<UserBoard> &prt);

    jarray getArray(Prt<vector<MahjongEnum>> &arrays);
    
private:
    JniEnv mEnv;
    jmethodID jBoardInfo_Init;
    jmethodID jBoardInfo_setMe;
    jmethodID jBoardInfo_setTop;
    jmethodID jBoardInfo_setDown;
    jmethodID jBoardInfo_setUp;
    jmethodID jMahjong_info;
    jmethodID jUserBoard_init;
    jmethodID jUserBoard_setBoard;
    jmethodID jUserBoard_setOpen;
    jmethodID jUserBoard_setOut;
    jmethodID jUserBoard_setIsDealer;
    jmethodID jUserBoard_setLackBoard;
    jmethodID jMahjong_simulateClick;
};


#endif //AUTOMAHJONG_NATIVE_LIB_H
